package gui_xmlparser;

import java.awt.Color;
import java.awt.Component;
import java.util.ArrayList;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * Rivera, Valencia, De Grano, Tan, Macatangay
 */
public class CellRenderer extends DefaultTableCellRenderer{

    private ArrayList<String> conceptComponents;
    private ArrayList<String> labelComponents;
            

    public CellRenderer(ArrayList<String> conceptComponents, ArrayList<String> labelComponents){
        this.conceptComponents = conceptComponents;
        this.labelComponents = labelComponents;
    }
    
    
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
    {
        Component cellComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        
        if(value.toString().toLowerCase().contains("adp")){
                cellComponent.setBackground(Color.BLUE);
        }

        else if(value.toString().toLowerCase().contains("adv")){
            cellComponent.setBackground(Color.MAGENTA);
        }

        else if(value.toString().toLowerCase().contains("np")){
            cellComponent.setBackground(Color.RED);
        }

        else if(value.toString().toLowerCase().contains("vp")){
            cellComponent.setBackground(Color.GRAY);
        }

        else if(value.toString().toLowerCase().contains("n")){
            cellComponent.setBackground(Color.ORANGE);
        }

        else if(value.toString().toLowerCase().contains("v")){
            cellComponent.setBackground(Color.GREEN);
        }
        
        for(int i =0; i<table.getRowCount();i++){
            if(table.getValueAt(row, 0).toString().contains(conceptComponents.get(i))){
                if(labelComponents.get(i).toLowerCase().contains("adp")){
                    cellComponent.setBackground(Color.BLUE);
                }
                
                else if(labelComponents.get(i).toLowerCase().contains("np")){
                    cellComponent.setBackground(Color.RED);
                }
                
                else if(labelComponents.get(i).toLowerCase().contains("adv")){
                    cellComponent.setBackground(Color.MAGENTA);
                }
                
                else if(labelComponents.get(i).toLowerCase().contains("vp")){
                    cellComponent.setBackground(Color.GRAY);
                }
                
                else if(labelComponents.get(i).toLowerCase().contains("n")){
                    cellComponent.setBackground(Color.ORANGE);
                }
                
                else if(labelComponents.get(i).toLowerCase().contains("v")){
                    cellComponent.setBackground(Color.GREEN);
                }
            }
        }
        
        return cellComponent;
    }
}
